package com.retailshop.shopuser.UserTask;

import com.retailshop.shopuser.service.HsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

@Controller
public class HsUserAuto {

    @Autowired
    HsUserService hsUserService;

    @ResponseBody
    @RequestMapping("/SyncHsUser")
    public String SyncHsUser(HttpServletRequest request,@RequestParam Map<String, Object> map) {

        String startTime = map.get("startTime")==null ? null:map.get("startTime").toString();
        String endTime = map.get("endTime")==null ? null:map.get("endTime").toString();

        String json = hsUserService.syncUser(startTime,endTime);

        return json;
    }

    @ResponseBody
    @RequestMapping("/SyncHsUser1")
    public String SyncHsUser1(HttpServletRequest request) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        Date t1 = c.getTime();
        String endTime =formatter.format(c.getTime());
        c.add(Calendar.HOUR_OF_DAY, -1);
        Date t2 = c.getTime();
        String startTime =formatter.format(c.getTime());

        System.out.println("startTime:"+startTime);
        System.out.println("endTime:"+endTime);

        String json = hsUserService.syncUser(startTime,endTime);

        return json;
    }

}
